package com.aaa.service.scl.Impl;

import com.aaa.dao.scl.SclRecordDao;
import com.aaa.entity.MyPage;
import com.aaa.entity.fpa.TjMessage;
import com.aaa.entity.scl.SclRecord;
import com.aaa.service.scl.SclRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * (SclRecord)表服务实现类
 *
 * @author makejava
 * @since 2022-10-27 19:11:05
 */
@Service
public class SclRecordServiceImpl implements SclRecordService {
   @Autowired
   private SclRecordDao sclRecordDao;

   /**
    * 分页查询所有数据
    * @param myPage
    * @param sclRecord
    * @return
    */
   @Override
   public List<SclRecord> queryAllRecord(MyPage myPage, SclRecord sclRecord) {
      PageHelper.startPage(myPage.getPage(), myPage.getLimit());
      List<SclRecord> sclRecords = sclRecordDao.queryAllRecord();
      return sclRecords;

   }

   /**
    * 详情信息
    * @param myPage
    * @param id
    * @return
    */
   @Override
   public PageInfo getDetailMsg(MyPage myPage, Integer id) {
      PageHelper.startPage(myPage.getPage(),myPage.getLimit());
      List<Map<String, Object>> queryxiangqing = sclRecordDao.queryxiangqing(id);
      PageInfo pageInfo = new PageInfo(queryxiangqing);
      return pageInfo;
   }

   /**
    * 查询电话号码
    * @param record
    * @return
    */
   @Override
   public SclRecord checkrecord(SclRecord record) {
      SclRecord sclRecord = sclRecordDao.selectOne(record);
      return sclRecord;
   }

   /**
    * 将记录添加到数据库
    * @param record
    * @return
    */
   @Override
   public int insertRecord(SclRecord record) {
      record.setCreatetime(new Date());
      int i = sclRecordDao.insert(record);
      System.out.println(record.getId());
      return record.getId();
   }

   /**
    * 模糊查询
    * @param myPage
    * @param sclRecord
    * @return
    */
   @Override
   public PageInfo querySclRecordAll(MyPage myPage, SclRecord sclRecord) {
      PageHelper.startPage(myPage.getPage(), myPage.getLimit());
      List<SclRecord> sclRecords = sclRecordDao.querySclRecordAll(sclRecord);
      PageInfo<SclRecord> sclRecordPageInfo = new PageInfo<>(sclRecords);
      return sclRecordPageInfo;
   }

   /**
    * 统计 F1~F2
    * @param myPage
    * @param tjMessage
    * @return
    */
   @Override
   public PageInfo getTj(MyPage myPage, TjMessage tjMessage) {
      PageHelper.startPage(myPage.getPage(),myPage.getLimit());
      List<Map<String, Object>> tj = sclRecordDao.getTj(tjMessage);
//      PageInfo<TjMessage> tjMessagePageInfo = new PageInfo<>();
      return new PageInfo(tj);
   }

}

